package day1;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * ClassName：CollectionTest3
 *
 * @Author：小鱼
 * @Create：2025-08-11 14:46
 */
public class CollectionTest3 {
    public static void main(String[] args) {
        Collection<String> coll1= new ArrayList<>();

        coll1.add("hello");
        coll1.add("world");
        coll1.add("!");


        //遍历集合，方法一
        Object[] arr = coll1.toArray();;
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

        //方法二：迭代器
        Iterator<String> iterator = coll1.iterator();
        while (iterator.hasNext()){
            String s = iterator.next();
            System.out.println(s);
        }

        //方法三：增强for循坏
        for (String s:coll1) {
            System.out.println(s);
        }
    }
}
